package com.feri.redromance01.service.impl;

import com.feri.redromance01.dao.DeparementDao;
import com.feri.redromance01.entity.Deparement;
import com.feri.redromance01.service.intf.DeparementService;
import com.feri.redromance01.util.StringUtil;
import com.feri.redromance01.vo.PageBean;

import com.feri.redromance01.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @autor wfl
 * @time 2022/8/30
 */
@Service
public class DeparementServiceImpl implements DeparementService {
    @Autowired
    private DeparementDao dao;

    @Override
    public R add(Deparement deparement) {
        if(dao.add(deparement)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(Deparement deparement) {
        if (dao.update(deparement)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R delete(int id) {
        if(dao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String name, int page, int limit) {
        if(StringUtil.isNotEmpty(name)){
            name="%"+name+"%";
        }
        int start =(page-1)*limit;
        return PageBean.ok(dao.selectCount(name),dao.selectPage(name, start, limit));
    }
}
